/**
 * 
 */
package vue.globalBar;

import java.awt.event.MouseEvent;

import model.session.PreprocessorExecutionBlock;
import vue.popup.JPopupPreprocessor;
import vue.session.IGPreprocessorBlock;
import controller.ISessionManager;

/**
 * 
 * A representation of a /preprocessor for the GlobalBar. It is somehow associate to
 * {@link PreprocessorExecutionBlock}.
 * 
 * @author GRONOWSKI Stephane svan001@aol.com
 * 
 *         igsat 2010
 * 
 */
public class IGBarPreprocessor extends IGBarExecution {


	private static final long	serialVersionUID	= 1L;

	private IGPreprocessorBlock	preproc;

	/**
	 * Create an {@link IGBarSolver}.
	 * 
	 * @param exec
	 *            the {@link IGPreprocessorBlock} associate
	 * @param manager
	 *            the session manager
	 */
	public IGBarPreprocessor(IGPreprocessorBlock exec, ISessionManager manager) {
		super(null, manager);

		this.preproc = exec;

		rightMenu = new JPopupPreprocessor(exec, manager);

		refresh();
	}

	/**
	 * Return the {@link IGPreprocessorBlock} associate.
	 * 
	 * @return the {@link IGPreprocessorBlock} associate.
	 */
	public IGPreprocessorBlock getPreproc() {
		return preproc;
	}

	@Override
	public void refresh() {
		description.setText(preproc.getPreproc().getPreproc().getType().getDescription());
		state.setText(preproc.getPreproc().getStatus().name());

		if (preproc.getPreproc().getRes() == null)
		{// pas de res
			time.setText(TIME_PREFIX + UNKNOW);
			memory.setText(MEMORY_PREFIX + UNKNOW);
		}
		else
		{// result dispo
			time.setText(TIME_PREFIX + preproc.getPreproc().getRes().getPreprocTime());
			memory.setText(MEMORY_PREFIX + preproc.getPreproc().getRes().getMemoryUsed());
		}

		rightMenu.refresh();
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		preproc.notifySelected();
	}

}
